window.onload = function() {
	var url = document.referrer;
	var resetEle = document.getElementById("reset");
	var loginEle = document.getElementById("login");
	var memory = document.getElementsByClassName("memory")[0];
	var userNameEle = document.getElementsByClassName("user-name")[0];
	var passwdEle = document.getElementsByClassName("passwd")[0];
	if (cookie.get("memoryFlag") == "true") {
		memory.checked = true;
		userNameEle.value = cookie.get("userName");
		passwdEle.value = cookie.get("passwd");
	}
	loginEle.addEventListener("click", function(e) {
		var userNameVal = userNameEle.value;
		var passwdVal = passwdEle.value;
		if (userNameVal == '' || userNameVal == undefined) {
			alert("用户名不能为空");
			return;
		} else if (passwdVal == '' || passwdVal == undefined) {
			alert("密码不能为空");
			return;
		} else {
			var xhr = new XMLHttpRequest();
			$.ajax({
				url: "http://127.0.0.1:8080/homework/user/login",
				method: "get",
				dataType: "json",
				data: {
					"username": "zhangsan",
					"passwd": "zhangsan"
				},
				sucess: function(res) {
					console.log("res: ", res);

				},
				error: function(error) {
					console.log("error: ", error);
				}
			});

			// if (memory.checked) {
			// 	cookie.set("memoryFlag", true, 15);
			// } else {
			// 	cookie.set("memoryFlag", false, 15);
			// }

			// cookie.set("userName", userNameVal, 15);
			// cookie.set("passwd", passwdVal, 15);

			// userNameEle.value = "";
			// passwdEle.value = "";
			// if (url == "" || url == undefined) {
			// 	location.href = "./index.html";
			// } else {
			// 	location.href = url;
			// }
		}
	});
	resetEle.addEventListener('click', function(e) {
		userNameEle.value = "";
		passwdEle.value = "";
	});
}